package com.ruibang.glass.produce.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.produce.constant.Constants;
import com.ruibang.glass.produce.domain.resp.MonitorInfo;
import com.ruibang.glass.produce.domain.resp.MonitorUpdate;
import com.ruibang.glass.produce.entity.MonitorPoint;
import com.ruibang.glass.produce.mapper.MonitorPointMapper;
import com.ruibang.glass.produce.service.MonitorPointService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-11-15  10:30
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Service
public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, MonitorPoint> implements MonitorPointService {


    /***
     * 根据监测点id集合查询设备监测点信息
     * @param monitorIds
     * @return
     */
    @Override
    public List<MonitorPoint> queryDataByIds(List<String> monitorIds) {
        return lambdaQuery().in(MonitorPoint::getMonitorId, monitorIds).list();
    }


    /**
     * @Description: 根据监测点code获取监测点信息
     * @version v1.0
     * @author songJinKang
     * @date 2023-11-15 14:44
     */
    @Override
    public List<MonitorInfo> getMonitorInfoByMonitorCode(List<String> monitorCodes) {
        if (CollectionUtils.isNotEmpty(monitorCodes)) {
            return baseMapper.getMonitorInfoByMonitorCode(monitorCodes);
        }
        return Collections.emptyList();
    }


    /***
     * 根据设备Id获取监测点信息
     * @param deviceId
     * @return
     */
    @Override
    public List<MonitorPoint> queryMonitorPoints(String deviceId) {
        return lambdaQuery().eq(MonitorPoint::getDeviceId, deviceId).eq(MonitorPoint::getStatus, Constants.ONE_INT)
                .orderBy(true, true, MonitorPoint::getOrderNum).list();
    }


    /***
     * 获取监测点信息
     * @param monitorIds
     * @return
     */
    @Override
    public List<MonitorPoint> queryByMonitorIds(List<String> monitorIds) {
        return lambdaQuery().in(MonitorPoint::getMonitorId, monitorIds).eq(MonitorPoint::getStatus, Constants.ONE_INT)
                .orderBy(true, true, MonitorPoint::getOrderNum).list();
    }

    /***
     * 根据设备Id删除监测点信息
     * @param deviceId
     */
    @Override
    public void deleteByDeviceId(String deviceId) {
        this.remove(lambdaQuery().eq(MonitorPoint::getDeviceId, deviceId).getWrapper());
    }


    /***
     * 更新排序码
     * @param monitorId
     */
    @Override
    public void updateOrderNum(String monitorId, Integer orderNum) {
        baseMapper.updateOrderNum(monitorId, orderNum);
    }


    /**
     * @Description: 根据设备ids获取监测点信息
     * @version v1.0
     * @author songJinKang
     * @date 2023-11-15 14:44
     */
    @Override
    public List<MonitorPoint> getMonitorPointByDeviceId(List<String> deviceIds) {
        return lambdaQuery().in(MonitorPoint::getDeviceId, deviceIds).eq(MonitorPoint::getStatus, Constants.ONE_INT).orderBy(true, true, MonitorPoint::getOrderNum).list();
    }

    @Override
    public void updateUnit(MonitorUpdate monitorUpdate) {
        baseMapper.updateUnit(monitorUpdate);
    }

    @Override
    public long getCountByDeviceId(String deviceId) {
        return lambdaQuery().eq(MonitorPoint::getDeviceId,deviceId).count();
    }
}
